<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
     //slice() 两个参数包起始不包结尾
     var arr2 = [1, 3, 5, 7, 9, 11];
    var arrCopy1 = arr2.slice(1); //[3, 5, 7, 9, 11]
    var arrCopy2 = arr2.slice(1, 4); //[3, 5, 7]
    var arrCopy3 = arr2.slice(1, -2); //slice(1,4)
    var arrCopy4 = arr2.slice(-4, -1); //slice(2,5)
    console.log(arrRemoved2); //[1, 3, 5, 7, 9, 11](原数组没变)
    console.log(arrCopy1); //[3, 5, 7, 9, 11]
    console.log(arrCopy2); //[3, 5, 7]
    console.log(arrCopy3); //[3, 5, 7]
    console.log(arrCopy4); //[5, 7, 9]

    //splice 改变原数组
    var arr = [1, 3, 5, 7, 9, 11];
    var arrRemoved = arr.splice(0, 2);
    console.log(arr); //[5, 7, 9, 11]
    console.log(arrRemoved); //[1, 3]

    var arrRemoved2 = arr.splice(2, 0, 4, 6);
    console.log(arr); //[1, 3, 4, 6, 5, 7, 9, 11]//在index2插入4，6
    console.log(arrRemoved2); //[]

    var arrRemoved3 = arr.splice(1, 1, 2, 4);
    console.log(arr); // [1, 2, 4, 5, 7, 9, 11] 在index1删除一个 再插入2，4
    console.log(arrRemoved3); //[3]
  </script>
</body>
</html>